package wildlife;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionMessage;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.*;
public class Registration {
	private String username,mailid,password,fullname,country,background;
	public String getFullname() {
		return fullname;
	}
	public void setFullname(String fullname) {
		this.fullname = fullname;
	}
	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
	}
	public String getBackground() {
		return background;
	}
	public void setBackground(String background) {
		this.background = background;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	long number;
public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getMailid() {
		return mailid;
	}
	public void setMailid(String mailid) {
		this.mailid = mailid;
	}
public String execute(){
	try{
		Connect c=new Connect();
		number = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
		checkrandom();
		c.dml("insert into users values('"+fullname+"','"+country+"','"+background+"','"+mailid+"','"+username+"','"+password+"',0,'"+number+"')");
		SendMail1 s=new SendMail1();
		s.to=mailid;
		s.message="<a href=\"http://192.16.11.114:8080/wildlife/Confirmation.action?cid="+number+"\">CLICK HERE </a>TO CONFIRM YOUR REGISTRATION";
		s.main();
		return "success";
	}catch(Exception e){e.printStackTrace();return "fail";}
}
public void checkrandom() throws Exception {
	Connect c=new Connect();
	ResultSet rs=c.getResult("select * from users where cid='"+number+"'");
	if(rs.next()){
		number = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
		checkrandom();
	}
	else{
		return ;
	}
}
}
